import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
//登录页路由
import Login from '@/pages/login/index'
//系统主页面路由
import Index from '@/components/index'
//系统主页面下子路由
import Home from '@/pages/home/index'

import User from '@/pages/user/index'
/******************************************************************************/
/**********************************赛事管理*************************************/
import Match from '@/pages/match/index'
//查看战绩
import ScoreAll from '@/pages/Match/Score/all'
import ScoreLoop from '@/pages/Match/Score/loop'
import ScoreKnock from '@/pages/Match/Score/knock'
//排战表
import Schedule from '@/pages/Match/Schedule/schedule'
import ScheduleAuto from '@/pages/Match/Schedule/scheduleAuto'
import ScheduleHandle from '@/pages/Match/Schedule/scheduleHandle'
import CheckSchedule from '@/pages/Match/Schedule/checkSchedule'
//检查&发布
import CheckKnock from '@/pages/Match/Check/checkKnock'
import CheckLoop from '@/pages/Match/Check/checkLoop'
import ReleaseKnock from '@/pages/Match/Check/releaseKnock'
import ReleaseLoop from '@/pages/Match/Check/releaseLoop'

//编排
import Layout from '@/pages/Match/Layout/layout'
import LayoutDraw from '@/pages/match/Layout/LayoutDraw'
import LayoutLoopHandle from '@/pages/match/Layout/layoutLoopHandle'
import LayoutHandDraw from '@/pages/match/Layout/LayoutHandDraw'
import LayoutKnockHandle from '@/pages/Match/Layout/layoutKnockHandle'
import LayoutKnockSignup from '@/pages/Match/Layout/layoutKnockSignup'
/*****************************************************************************/
import Question from '@/pages/question/index'

import Permission from '@/pages/permission/index'

//match下子路由
import AddNewMatch from '@/pages/match/AddNewMatch'
import MatchHome from '@/pages/match/MatchHome'
import AddMatchDetail from '@/pages/match/ListManageReferee/AddMatchDetail'
//查看赛事
import MatchSignUp from '@/pages/match/ListManageSignUp/MatchSignUp'
import MatchDetail from '@/pages/match/ListManageSignUp/MatchDetail'
import TreeMap from '@/components/TreeMap'

export default new Router({
  routes: [
    {
      path: '/',
      redirect:'Index'
    },
    {
      path: '/Index',
      component: Index,
      children:[
        {
          path: '',
          redirect:'Home'
        },
        {
          path: 'User',
          component: User
        },
        {
          path: 'Permission',
          component: Permission
        },
        {
          path: 'Question',
          component: Question
        },
        {
          path: 'Match',
          component: Match,
          children:[
            {
              path:'',
              component:MatchHome,
            },
            //添加新赛事
            {
              path:'AddNewMatch',
              component:AddNewMatch
            },
            //添加赛事详情
            {
              path:'AddMatchDetail',
              component:AddMatchDetail,
            },
            //查看成绩
            {
              path:'MatchDetail',
              component:MatchDetail,
            },
            {
              path:'MatchSignUp',
              component:MatchSignUp,
            },
            {
              path:'scoreall',
              component:ScoreAll
            },
            {
              path:'scoreloop',
              component:ScoreLoop
            },
            {
              path:'scoreknock',
              component:ScoreKnock
            },
            //排战表
            {
              path:'scheduleAuto',
              component:ScheduleAuto
            },
            {
              path:'schedule',
              component:Schedule
            },
            {
              path:'scheduleHandle',
              component:ScheduleHandle
            },
            {
              path:'checkSchedule',
              component:CheckSchedule
            },
            //发布检查
            {
              path:'checkLoop',
              component:CheckLoop
            },
            {
              path:'checkKnock',
              component:CheckKnock
            },
            {
              path:'releaseLoop',
              component:ReleaseLoop
            },
            {
              path:'releaseKnock',
              component:ReleaseKnock
            },
            //编排
            {
              path:'layout',
              component:Layout,
            },
            {
              path:'LayoutDraw',
              component:LayoutDraw,
            },
            {
              path: 'LayoutLoopHandle',
              component: LayoutLoopHandle,
            },
            {
              path:'LayoutHandDraw',
              component:LayoutHandDraw,
            },
            {
              path:'LayoutKnockHandle',
              component:LayoutKnockHandle,
            },
            {
              path:'LayoutKnockSignup',
              component:LayoutKnockSignup,
            }
          ],
        },
        {
          path: 'Home',
          component:Home
        },
      ]
    },
    {
      path: '/Login',
      component: Login
    },
    {
      path: '/Test',
      component:TreeMap,
    }
  ]
})
// // 全局路由守卫
// router.beforeEach((to, from, next) => {
//   console.log('navigation-guards');
//   // to: Route: 即将要进入的目标 路由对象
//   // from: Route: 当前导航正要离开的路由
//   // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。

//   const nextRoute = ['home', 'good-list', 'good-detail', 'cart', 'profile'];
//   let isLogin = global.isLogin;  // 是否登录
//   // 未登录状态；当路由到nextRoute指定页时，跳转至login
//   if (nextRoute.indexOf(to.name) >= 0) {  
//     if (!isLogin) {
//       console.log('what fuck');
//       router.push({ name: 'login' })
//     }
//   }
//   // 已登录状态；当路由到login时，跳转至home 
//   if (to.name === 'login') {
//     if (isLogin) {
//       router.push({ name: 'home' });
//     }
//   }
//   next();
// });